import React from 'react'
// ===================================================================== Temp
import FormModal from '#cpt/temp/FormModal'
// ===================================================================== Declare
const { $fn, $Lazy } = window
// ===================================================================== Lazy
const $cache = $Lazy.file(()=>import('#private/cache-api'))
// ===================================================================== component
class Index extends React.Component{
	state = {
		rows:{},
		// 提交表单列表
		formData : [
			{ label:' ', tag: '是否生成迟发通知书',			name: 'is_delay_report', 		full:true, 	type:'checkbox', value:1 },
			{ label: '预计报告时间',			name: 'delay_at', 		full:true, 	required:true, type:'date-time', format:1, before:true  },
			{ label: '异常原因类型',			name: 'abnormal_type', 	full:true, 	required:true, type: 'select', idStr:'code', onValue:({ rows, value, ref})=>{
				ref.setValue({ reason: +value !== 62051 ? rows['desc'] : '' })
			} },
			{ label: '原因',        		name: 'reason', 		full:true, 	required:true, type:'textarea'},
		]
	}
	
	model = {}
	
	open = (name, rows) => {
		const { formData } = this.state
		this.modal.open({ formRef:this.formRef })
		
		if(name !== '迟发'){
			$fn.hideRows(formData, ['delay_at', 'is_delay_report'], true)
		}else{
			$fn.hideRows(formData, ['delay_at', 'is_delay_report'], false)
			this.formRef.setValue({ is_delay_report:1 })
		}
		
		this.getModalSelect(name)
		
		this.rows = rows
		
		this.submit = { ...rows.param }
		
		this.setState({ name,  formData })
	}
	// 获取弹框下拉
	getModalSelect = async (name) => {
		const { formData } = this.state
		let code
		switch (name) {
			case '迟发':
				code = 70500
				break;
			case '退单':
				code = 70550
				break;
			case '项目终止':
				code = 70600
				break;
			default:
				break;
		}
		$cache.then( async f => {
			// 异常原因类型
			$fn.setRow(formData, 'abnormal_type', await f.getDicCache({ code }))
			this.setState({ formData })
		})
	}
	render(){
		const { name } = this.state
		const { api, clear } = this.rows || {}
		return FormModal.call(this,{ title: name, labelWidth:'s7',  width:600, api, clear})
	}
}

export default Index